from django.db import models
from db.base_model import BaseModel

# Create your models here.

class OrderInfo(BaseModel):
    '''订单模型类'''
    PAY_METHOD_CHOICES = (
        (0,'货到付款'),
        (1,'微信支付'),
        (2,'支付宝'),
        (3,'银联支付'),
    )

    ORDER_STATUS_CHOICES = (
        (0,'待支付'),
        (1,'待发货'),
        (2,'待收获'),
        (3,'待评价'),
        (4,'已完成'),
    )

    ORDER_STATUS = {
        0: '待支付',
        1: '待发货',
        2: '待收获',
        3: '待评价',
        4: '已完成',
    }

    order_id = models.CharField(max_length=128, primary_key=True)
    user = models.ForeignKey('user.User', on_delete=models.CASCADE)
    addr = models.ForeignKey('user.Address', on_delete=models.CASCADE)
    pay_method = models.SmallIntegerField(default=2,choices=PAY_METHOD_CHOICES)
    total_count = models.IntegerField(default=1)
    total_price = models.DecimalField(max_digits=10, decimal_places=2)
    trans_price = models.DecimalField(max_digits=10, decimal_places=2)
    order_status = models.SmallIntegerField(default=0, choices=ORDER_STATUS_CHOICES)
    trade_nu = models.CharField(max_length=128, default='')

    class Meta:
        db_table = 'df_order_info'
        verbose_name = '订单模型类'
        verbose_name_plural = verbose_name


class OrderGoods(BaseModel):
    '''订单商品模型类'''
    order = models.ForeignKey('OrderInfo', on_delete=models.CASCADE)
    sku = models.ForeignKey('goods.GoodsSKU', on_delete=models.CASCADE)
    count = models.IntegerField(default=1)
    price = models.DecimalField(max_digits=10, decimal_places=2)
    comment = models.CharField(max_length=256, default='')

    class Meta:
        db_table = 'df_order_goods'
        verbose_name = '订单商品模型类'
        verbose_name_plural = verbose_name

